//
//  CourseSearchHistoryHeader.m
//  ShowYork
//
//  Created by hxh on 2020/8/30.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "LessonSearchHeader.h"

@interface LessonSearchHeader ()
@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,strong)UIImageView *removeImgView;
@property (nonatomic,strong)UIButton *removeBtn;
@end

@implementation LessonSearchHeader
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
    
    self.titleLb = [[UILabel alloc]init];
    self.titleLb.font = [UIFont boldSystemFontOfSize:18];
    self.titleLb.text = @"历史搜索";
    self.titleLb.textColor = RGBA(35, 24, 21, 1);
    [self addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(20);
    }];

    self.removeImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"course_delete"]];
    [self addSubview:self.removeImgView];
    [self.removeImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-16);
        make.centerY.equalTo(self.titleLb);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    
    
    self.removeBtn = [[UIButton alloc]init];
    [self.removeBtn addTarget:self action:@selector(removeMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.removeBtn];
    [self.removeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLb);
        make.right.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
}

- (void)removeMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(removeSearchData)]) {
        [self.delegate removeSearchData];
    }
}
- (void)setHeaderTitle:(NSString *)title andShowDeleteButton:(BOOL)isShow{
    self.removeImgView.hidden = !isShow;
    self.removeBtn.hidden = !isShow;
    self.titleLb.text = title;
}
@end
